#include <iostream>
#include <math.h>


using namespace std;

int main()
{
  float simpleequation(float a ,float b);
  float quadraticequation(float a ,float b,float c);
  int n;
  cout<<"input the number:n"<<endl;
  cin>>n;
  cout<<"the degree of equation="<<n<<endl;
  if (n==1)
  {
     float coeff1,coeff2;
     cout<<"input two numbers:"<<endl;
     cin>>coeff1>>coeff2;
     simpleequation(coeff1,coeff2);
  }
  else if (n==2)
  {
       float coeff3,coeff4,coeff5;
       cout<<"input three numbers:"<<endl;
       cin>>coeff3>>coeff4>>coeff5;
       quadraticequation(coeff3,coeff4,coeff5);

   }
return 0;
}

float simpleequation(float a,float b)
{   float x;
    if (a!=0)
        {x=-b/a ;
        cout<<"the equation result="<<x<<endl;}
     else if ((a==0)&&(b==0))
        cout<<"the equation has  infinitude results"<<endl;
     else if ((a==0)&&(b!=0))
        cout<<"the equation has no result"<<endl;

     return 0;
}

float quadraticequation(float a,float b,float c)
{
    float x1,x2,tm,pm,ym,rm;;
    tm=b*b-4*a*c;
    if (a==0)
         simpleequation(b,c);
    else if ((tm>=0)&&(a!=0))
        {pm=sqrt(tm);
        x1=(-b+pm)/(2*a);
        x2=(-b-pm)/(2*a);
        cout<<"the equation has two real result:x1="<<x1<<",x2="<<x2<<endl;}
    else if ((tm<0)&&(a!=0))
        {
        ym=(-b)/(2*a);
        rm=sqrt(-tm)/(2*a);
        cout<<"the equation has two umresl result:x1="<<ym<<"+j*"<<rm<<",x2="<<ym<<"+j*"<<-rm<<endl;}
   return 0;


}
